package com.newsinfo.mapper;

import com.newsinfo.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //根据用户名查询用户
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);
    //注册
    @Insert("insert into user(username,password,create_time,update_time) values (#{username},#{password},now(),now())")
    void register(String username, String password);
    //更新用户基本信息
    @Update("update user set nickname = #{nickname}, email = #{email}, update_time = now() where id = #{id}")
    void updateUserInfo(User user);
    //更新用户头像
    @Update("update user set user_pic = #{avatarUrl}, update_time = now() where id = #{userId}")
    void updateAvatar(String avatarUrl, Integer userId);
    //更新用户密码
    @Update("update user set password = #{md5NewPwd}, update_time = now() where id = #{userId}")
    void updatePwd(String md5NewPwd, Integer userId);
}
